package com.edu.exam.entity.curriculum.questionbank;

import com.edu.exam.enums.curriculum.questionbank.AssociationSource;
import com.edu.exam.enums.curriculum.questionbank.AssociationStrength;
import com.edu.exam.enums.curriculum.questionbank.Relevance;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 试题标签关联实体类
 * 对应数据库表：question_tag_assoc
 *
 * 管理试题与标签的关联关系，包括关联权重、相关度等。
 * 支持试题的多标签关联和标签的使用统计。
 * 提供完整的关联关系管理功能。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("试题标签关联表")
@SQLDelete(sql = "UPDATE question_tag_assoc SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class QuestionTagAssoc {

    /**
     * 关联记录唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 试题ID
     */
    @NotNull(message = "试题ID不能为空")
    @Column(name = "question_id", nullable = false)
    private Long questionId;

    /**
     * 标签ID
     */
    @NotNull(message = "标签ID不能为空")
    @Column(name = "tag_id", nullable = false)
    private Long tagId;

    /**
     * 关联权重
     */
    @NotNull(message = "关联权重不能为空")
    @Column(name = "weight", nullable = false, precision = 3, scale = 2)
    @Builder.Default
    private BigDecimal weight = BigDecimal.ONE;

    /**
     * 相关度
     */
    @NotNull(message = "相关度不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "relevance", nullable = false, length = 20)
    private Relevance relevance;

    /**
     * 关联强度
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "association_strength", length = 20)
    private AssociationStrength associationStrength;

    /**
     * 关联说明
     */
    @Column(name = "association_description", length = 500)
    private String associationDescription;

    /**
     * 关联来源
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "association_source", length = 20)
    private AssociationSource associationSource;

    /**
     * 关联置信度
     */
    @Column(name = "confidence_level", precision = 3, scale = 2)
    private BigDecimal confidenceLevel;

    /**
     * 关联优先级
     */
    @Column(name = "priority")
    @Builder.Default
    private Integer priority = 0;

    /**
     * 关联标签
     */
    @Column(name = "association_tags", length = 200)
    private String associationTags;

    /**
     * 关联元数据，JSON格式
     */
    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata;

    /**
     * 记录创建时间
     */
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 创建人用户ID
     */
    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 乐观锁版本号
     */
    @Version
    @Column(name = "version", nullable = false)
    @Builder.Default
    private Integer version = 1;

    /**
     * 软删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    }